'use strict';

module.exports = app => {
  const { STRING, INTEGER, TEXT, DATE } = app.Sequelize;

  const EmployerInfo = app.model.define('employer_info', {
    id: {
      type: INTEGER,
      primaryKey: true,
      autoIncrement: true,
    },
    user_id: {
      type: INTEGER,
      allowNull: false,
      references: {
        model: 'users',
        key: 'user_id'
      }
    },
    name: {
      type: STRING(255),
      comment: '企业名称'
    },
    avatar: {
      type: STRING(255),
      comment: '企业头像'
    },
    legal_representative: {
      type: STRING(255),
      comment: '法定代表人名称'
    },
    establishment_date: {
      type: DATE,
      comment: '成立日期'
    },
    address: {
      type: STRING(255),
      comment: '注册地址'
    },
    business_license_number: {
      type: STRING(255),
      comment: '营业执照号码'
    },
    tax_id: {
      type: STRING(255),
      comment: '纳税人识别号'
    },
    phone_number: {
      type: STRING(255),
      comment: '联系电话'
    },
    description: {
      type: STRING(255),
      comment: '企业描述'
    },
    photos_url: {
      type: TEXT,
      comment: '环境照片'
    },
    created_at: DATE,
    updated_at: DATE,
  }, {
    timestamps: true,
    tableName: 'employer_info',
  });

  EmployerInfo.associate = function() {
    app.model.EmployerInfo.belongsTo(app.model.User, {
      foreignKey: 'user_id',
      targetKey: 'user_id'
    });
  };

  return EmployerInfo;
};
